﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Knlght.Domain
{
    /// <summary>
    /// 查询条件请求
    /// </summary>
    public class QueryRequest<T>
    {
        public QueryRequest()
        {
            SubQueries= PredicateExtensionses.True<T>();
            OrderBys = new Dictionary<string, bool>();
        }
        /// <summary>
        /// 查询条件集合
        /// </summary>
        public Expression<Func<T, bool>> SubQueries { get; set; }
        public Dictionary<string, bool> OrderBys { get; set; }      
        public void Add(Expression<Func<T, bool>> exp)
        {
            SubQueries = SubQueries.And(exp);
        }
        public void AddOrder(string propertyName, bool isAsce)
        {
            OrderBys.Add(propertyName, isAsce);
        }
    }
    /// <summary>
    /// 条件表达式
    /// </summary>
    public class CriterionRequest
    {
        public CriterionRequest()
        {
            CriteriaOp = CriteriaOP.Equal;
            LogicOp = LogicOP.And;
        }

        /// <summary>
        /// 属性名
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 属性值
        /// </summary>
        public object Value { get; set; }
        /// <summary>
        /// 条件运算符
        /// </summary>
        public CriteriaOP CriteriaOp { get; set; }
        /// <summary>
        /// 逻辑运算符
        /// </summary>
        public LogicOP LogicOp { get; set; }
    }
    /// <summary>
    /// 排序表达式
    /// </summary>
    public class OrderByRequest
    {
        /// <summary>
        /// 排序的属性名称 
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 排序运算符
        /// </summary>
        public OrderOP OrderOp { get; set; }
    }
    /// <summary>
    /// 排序运算符
    /// </summary>
    public enum OrderOP
    {
        Asc = 1,
        Desc = 2
    }
    /// <summary>
    /// 逻辑运算符
    /// </summary>
    public enum LogicOP
    {
        /// <summary>
        /// 逻辑与
        /// </summary>
        And,
        /// <summary>
        /// 逻辑或
        /// </summary>
        Or
    }
    /// <summary>
    /// 条件运算符
    /// </summary>
    public enum CriteriaOP
    {
        /// <summary>
        /// 等于
        /// </summary>
        Equal = 0,
        /// <summary>
        /// 不等于
        /// </summary>
        NotEqual = 1,
        /// <summary>
        /// 大于
        /// </summary>
        GreatThan = 2,
        /// <summary>
        /// 大于等于
        /// </summary>
        GreatThanEqual = 3,
        /// <summary>
        /// 小于
        /// </summary>
        LessThan = 4,
        /// <summary>
        /// 小于等于
        /// </summary>
        LessThanEqual = 5,
        /// <summary>
        /// 匹配
        /// </summary>
        Like = 6,
        /// <summary>
        /// 左匹配
        /// </summary>
        LeftLike = 7,
        /// <summary>
        /// 右匹配
        /// </summary>
        RightLike = 8,
        /// <summary>
        /// 不匹配
        /// </summary>
        NotLike = 9,
        /// <summary>
        /// 包含
        /// </summary>
        In = 10,
        /// <summary>
        /// 不包含
        /// </summary>
        NotIn = 11,
        /// <summary>
        /// 区间
        /// </summary>
        Between = 12,
        /// <summary>
        /// 非区间
        /// </summary>
        NotBetween = 13
        ///// <summary>
        ///// 空
        ///// </summary>
        //Null = 14,
        ///// <summary>
        ///// 非空
        ///// </summary>
        //NotNull = 15,
    }
}
